<script>
export default {
    name: 'SnowEffect',
    data() {
        return {};
    },
    methods: {}
};
</script>

<template>
    <div class="snow">
        <div class="snowflake" v-for="i in 200" :key="i">❅</div>
    </div>
</template>

<style scoped lang="scss">
.snow {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
    background: black;
    &:before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: linear-gradient(to bottom, #fff 20%, rgba(255, 255, 255, 0)) no-repeat center center;
        background-size: cover;
        opacity: 0.5;
    }
    .snowflake {
        position: absolute;
        color: #fff;
        @for $i from 0 through 200 {
            $key: $i + 1;
            &:nth-child(#{$key}) {
                $row: floor($i / 20);
                font-size: random(30) + 10px;
                top: random(768) + 1px;
                left: random(1920) + 1px;
                animation: snow#{$i} random(10000) + 1000ms linear infinite normal; // infinite 动画无限循环 linear 动画匀速 alternate 动画在奇数次（1、3、5...）正向播放，在偶数次（2、4、6...）反向播放
                filter: blur(#{random(15) - 10}px);
                @keyframes snow#{$i} {
                    0% {
                        transform: translateY(0) rotate(0deg);
                        opacity: 1;
                    }
                    20% {
                        transform: translateY(60px) rotate(random(360) + 30deg);
                        opacity: 1;
                    }
                    40% {
                        transform: translateY(120px) rotate(random(360) + 30deg);
                        opacity: 1;
                    }
                    60% {
                        transform: translateY(180px) rotate(random(360) + 30deg);
                        opacity: 0.8;
                    }
                    80% {
                        transform: translateY(240px) rotate(random(360) + 30deg);
                        opacity: 0.5;
                    }
                    100% {
                        transform: translateY(300px) rotate(360deg);
                        opacity: 0;
                    }
                }
            }
        }
    }
}
</style>
